-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Rework WiFiClient #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rework WiFiClient #238
Conversation
Rework WiFiClient to correct error where making a copy of a WiFiClient object resulted in the socket being closed prematurely. Added loop and select to write to handle/prevent EAGAIN errors.
There are generally two ways to tackle issues like that. I would rather use shared pointer which will manage the state on it's own, will clean the code and you will not have to worry to ref/unref count. |
Interesting, I hadn't been aware of shared pointers (I'm mostly a C developer). I agree that looks like it will be a cleaner implementation, I'll work on that change and move the changes to write to a separate PR. |
Rework changes to utilize shared_ptr rather than manually maintaining reference count. Revert changes to write
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice :) just a few comments :)
libraries/WiFi/src/WiFiClient.h
Outdated
#include "Arduino.h" | ||
#include "Client.h" | ||
#include <memory> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can move the whole class in the CPP and only forward declare it here. It's private really and users do not need to bother with it.
libraries/WiFi/src/WiFiClient.cpp
Outdated
@@ -199,52 +165,21 @@ int WiFiClient::read() | |||
|
|||
size_t WiFiClient::write(const uint8_t *buf, size_t size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to sync this code now with the one that I already merged :)
libraries/WiFi/src/WiFiClient.h
Outdated
@@ -69,21 +87,26 @@ class WiFiClient : public Client | |||
return !this->operator==(rhs); | |||
}; | |||
|
|||
int fd() | |||
int fd() const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should go into the CPP
Conflicts: libraries/WiFi/src/WiFiClient.cpp
Move WiFiClientSocketHandle and fd() into WiFiClient.cpp
great work :) maybe you want to look at WiFiClientSecure? |
Yup, looks like WiFiClientSecure has the same issue. I'll see what I can do. |
udp probably suffers from that same thing :D |
Rework WiFiClient to correct error where making a copy of a WiFiClient object resulted in the socket being closed prematurely.
Added loop and select to write to handle/prevent EAGAIN errors.